<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main2"/>
    <g:set var="entityName" value="${message(code: 'menu.label', default: 'Menu')}"/>
    <title>菜单列表</title>
</head>

<body>
<div class="main-body">
    <div class="page-wrapper">
        <!-- Page-header start -->
        <div class="page-header">
            <div class="page-header-title">
                <h4>菜单列表</h4>
            </div>

            <div class="page-header-breadcrumb">
                <ul class="breadcrumb-title">
                    <li class="breadcrumb-item">
                        <a href="/salesDashboard/index">
                            <i class="icofont icofont-home"></i>
                        </a>
                    </li>
                    <li class="breadcrumb-item"><a href="#!">菜单列表</a>
                    </li>
                </ul>
            </div>
        </div>
        <!-- Page-header end -->
        <!-- Page-body start -->
        <div class="page-body">
            <!-- Hover table card start -->
            <div class="card">
                <div class="card-header">
                    <h5>菜单列表</h5>

                    <div class="card-header-right">
                        <g:link action="create" data-toggle="tooltip" data-placement="top"
                                title="新增" data-original-title="新增">
                            <i class="icofont icofont-plus"></i>
                        </g:link>
                        <i class="icofont icofont-rounded-down"></i>
                    </div>
                </div>

                <div class="card-block dt-responsive">

                    <div class="table-responsive">
                        <div id="dom-jqry_wrapper" class="dataTables_wrapper dt-bootstrap4">

                            <table class="table table-striped  table-bordered table-hover">
                                <thead>
                                <tr>
                                    <g:sortableColumn property="name" title="名称"/>
                                    <!--  <th width="10%">
                              
                               <input type="checkbox" class="clickFather">
                               <button id="clickBtn" class="btn btn-danger btn-xs" disabled type="button">批量删除</button>
                               
                           </th> -->
                                    <th width="15%" class="text-center">操作</th>
                                </thead>
                                <tbody>
                                <g:each in="${menuList}">
                                    <tr>
                                        <td>
                                            <g:link controller="menu" action="show" id="${it?.id}">${it?.name}
                                            </g:link></td>
                                        %{-- <th><input type="checkbox" class="clickSon" value="${it?.id}"></th> --}%

                                        <td class="text-center">
                                            <g:link class="m-r-15 text-primary"
                                                    controller="menu" action="edit"
                                                    id="${it?.id}">
                                                <i class="icofont icofont-ui-edit"></i>
                                            </g:link>

                                            <g:form controller="menu" action="delete" class="inline"
                                                    id="${it.id}" method="DELETE">
                                                <button class="deleteBtn text-danger" type="button">
                                                    <i class="icofont icofont-trash"></i>
                                                </button>
                                            </g:form>

                                        </td>

                                    </tr>
                                </g:each>
                                </tbody>
                            </table>

                            <div class="dataTables_paginate">
                                <div class="pagination">
                                    <g:paginate total="${menuCount ?: 0}"/>
                                </div>
                            </div>
                        </div>

                    </div>

                </div>
            </div>
            <!-- Hover table card end -->
        </div>

        <!-- Page-body end -->
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $(".clickFather").click(function () {
            var sons = $(".clickSon");
            for (var i = 0; i < sons.length; i++) {
                sons[i].checked = $(this)[0].checked;
                if (sons[i].checked) {
                    $("#clickBtn").removeAttr("disabled");
                } else {
                    $("#clickBtn").attr("disabled", "disabled")
                }
            }


        });
        $(".clickSon").click(function (event) {
            var sons = $(".clickSon");
            var num = 0;
            for (var i = 0; i < sons.length; i++) {
                if (sons[i].checked) {
                    num++;
                }
            }

            if (sons.length == num) {
                $(".clickFather")[0].checked = true;
            } else {
                $(".clickFather")[0].checked = false;
            }

            if (num > 0) {
                $("#clickBtn").removeAttr('disabled');
            } else {
                $("#clickBtn").attr("disabled", "disabled");
            }
        });
        $("#clickBtn").click(function () {
            var menuIds = [];
            var sons = $(".clickSon");
            for (var i = 0; i < sons.length; i++) {
                if (sons[i].checked) {
                    menuIds.push(sons[i].value);
                }
            }
            /* $.ajax({
             type: "POST",
             dataType: "json",
             url:"/menu/batchDelete",
             data:{
             menuIds:menuIds.join(",")
             },
             success: function (data) {
             alert(data)
             if (data.status == "success") {
             window.history.go(0);
             }
             },
             })*/
            $.post("/menu/batchDelete", {menuIds: menuIds.join(",")}, function (data) {
                if (data.status == "success") {
                    window.location.history(0);
                }
            });

        });


    });
</script>
</body>
</html>